//
//  MerchantEventCell.m
//  ImGuider
//
//  Created by 李陆涛 on 2018/6/14.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "MerchantEventCell.h"
#import "UIView+Gradient.h"

@interface MerchantEventCell ()

@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *discountLabel;

@property (weak, nonatomic) IBOutlet UIButton *buyBtn;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *desLabel;
@property (weak, nonatomic) IBOutlet UIView *borderView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgHeight;

@end

@implementation MerchantEventCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.borderView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.borderView.layer.borderWidth = 1.0f;
    
    self.bgHeight.constant = (kScreenWidth - 32)/84 * 29;
    
    [self.bgView gradientWithColorArray:@[[UIColor colorWithHexString:@"#017EC9"], [UIColor colorWithHexString:@"#00B8E4"]] frame:CGRectMake(0, 0, (kScreenWidth - 32), (kScreenWidth - 32)/84 * 29) isLeftToRight:YES];
    
    if (ISiPhone5 | ISiPhone4) {
        self.desLabel.font = Font(9);
        self.discountLabel.font = Font(32);
    }
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //    [self.buyBtn setTitle:@"查看详情" forState:UIControlStateNormal];
}

- (void)setModel:(MerchantEventModel *)model {
    
//        model.typeNum = @"1";
//        model.discountNum = @"9";
//        model.freeNum = @"10000";
//        model.moneyType = @"￥";
//        model.useTip = @"所有商品全场9折";
    _model = model;
    
    //    CGFloat width = [IGUtil getSizeContent:model.type width:1000 font:Font(12)].width + 15;
    //
    //    self.tagLabelW.constant = width;
    //
    //    self.nameLabel.text = model.name;
    //    self.tagLabel.text = model.type;
    
    
    NSMutableAttributedString *typeAtt = [[NSMutableAttributedString alloc] initWithString:@"ImGuider"];
    typeAtt.color = [UIColor whiteColor];
    typeAtt.font = Font(14);
    [typeAtt appendString:@"\n"];
    typeAtt.alignment = NSTextAlignmentCenter;
    typeAtt.lineSpacing = 5;
    
    NSInteger typeNum = model.typeNum.integerValue;
    
    switch (typeNum) {
        case 1: {
            
            NSMutableAttributedString *couponTypeAtt = [[NSMutableAttributedString alloc] initWithString:@"专属优惠券"];
            couponTypeAtt.font = Font(18);
            [typeAtt appendAttributedString:couponTypeAtt];
            
            self.typeLabel.attributedText = typeAtt;
            
            
            NSMutableAttributedString *discountAtt = [NSMutableAttributedString new];
            
            NSMutableAttributedString *moneyType = [[NSMutableAttributedString alloc] initWithString:model.moneyType];
            moneyType.font = Font(20);
            
            [discountAtt appendAttributedString:moneyType];
            
            NSMutableAttributedString *moneyAtt = [[NSMutableAttributedString alloc] initWithString:model.freeNum];
            moneyAtt.font = Font(48);
            
            [discountAtt appendAttributedString:moneyAtt];
            
            self.discountLabel.attributedText = discountAtt;
        }
            break;
        case 2: {
            
            NSMutableAttributedString *couponTypeAtt = [[NSMutableAttributedString alloc] initWithString:@"专属折扣券"];
            couponTypeAtt.font = Font(18);
            [typeAtt appendAttributedString:couponTypeAtt];
            
            self.typeLabel.attributedText = typeAtt;
            
            
            NSMutableAttributedString *discountAtt = [NSMutableAttributedString new];
            
            NSMutableAttributedString *moneyAtt = [[NSMutableAttributedString alloc] initWithString:model.discountNum];
            moneyAtt.font = Font(48);
            
            [discountAtt appendAttributedString:moneyAtt];
            
            
            NSMutableAttributedString *moneyType = [[NSMutableAttributedString alloc] initWithString:@"折"];
            moneyType.font = Font(20);
            
            [discountAtt appendAttributedString:moneyType];
            
            self.discountLabel.attributedText = discountAtt;
            
        }
            break;
            
        default: {
            
            NSMutableAttributedString *couponTypeAtt = [[NSMutableAttributedString alloc] initWithString:@"专属优惠券"];
            couponTypeAtt.font = Font(18);
            [typeAtt appendAttributedString:couponTypeAtt];
            
            self.typeLabel.attributedText = typeAtt;
            
            NSMutableAttributedString *discountAtt = [[NSMutableAttributedString alloc] initWithString:@"限时特惠"];
            discountAtt.font = Font(20);
            self.discountLabel.attributedText = discountAtt;
        }
            break;
    }
    self.desLabel.text = model.useTip;
    
}

@end

